package com.woparker.kiosk.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 *
 * @ClassName: CommonAdapter
 * @Description: TODO(万能适配器)
 * @author yxd
 *
 * @param <T>
 */
public abstract class CommonAdapter<T> extends BaseAdapter
{
    protected LayoutInflater mInflater;
    protected Context mContext;
    protected List<T> mDatas;
    protected final int mItemLayoutId;
    protected boolean isLoadNetImage;
    ViewHolder viewHolder;
    /**
     *
     * @param context
     * @param mDatas
     * @param itemLayoutId
     * @param isLoadNetImage
     */
    public CommonAdapter(Context context, List<T> mDatas, int itemLayoutId,boolean isLoadNetImage)
    {
        this.mContext = context;
        this.mInflater = LayoutInflater.from(mContext);
        this.mDatas = mDatas;
        this.mItemLayoutId = itemLayoutId;
        this.isLoadNetImage = isLoadNetImage;
    }

    @Override
    public int getCount()
    {
        return mDatas.size();
    }

    @Override
    public T getItem(int position)
    {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        viewHolder = getViewHolder(position, convertView,
                parent,isLoadNetImage);
        convert(viewHolder, getItem(position));
        return viewHolder.getConvertView();
    }

    public abstract void convert(ViewHolder viewHolder, T item);

    private ViewHolder getViewHolder(int position, View convertView,
                                     ViewGroup parent,boolean isLoadNetImage)
    {
        return ViewHolder.get(mContext, convertView, parent, mItemLayoutId,
                position,isLoadNetImage);
    }


}  
